package com.scott.classicthreadmodal.demo2.consumer;

import com.scott.classicthreadmodal.demo2.storage.IStorage;

public class Consumer implements Runnable {

    /**
     * 消费者名称
     */
    private String name;

    /**
     * 需求数量
     */
    private int num;

    private IStorage storage;

    public Consumer(String name, int num, IStorage storage) {
        this.name = name;
        this.num = num;
        this.storage = storage;
    }

    @Override
    public void run() {

        try {
            while (true) {
                storage.consume(getNum(), getName());
                System.out.println(Thread.currentThread().getName()+":【" + getName() + "】消费了:" + getNum() + "【现仓储量为】:" + storage.getStock());
                Thread.sleep(2000);
            }
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getNum() {
        return num;
    }

    public void setNum(int num) {
        this.num = num;
    }

    public IStorage getStorage() {
        return storage;
    }

    public void setStorage(IStorage storage) {
        this.storage = storage;
    }
}
